#include <stdio.h>
#define MaxSize 100
typedef  int DataType;

typedef struct
{
    DataType list[MaxSize];
    int size;
}  SeqList;

void  ListInitiate(SeqList *L)
{
    L->size = 0;
}

int ListLength(SeqList L)
{
    return L.size;
}

int ListInsert(SeqList *L,int i,DataType x)
{
    int j;
    if(L->size >= MaxSize)
    {
        printf("sequence table cannot be inserted！\n");
        return 0;
    }
    else if(i < 0||i >L-> size)
    {
        printf("parameter i wrongful！\n");
        return 0;
    }
    else
    {
        L->size++;
        for(j=L->size;j>i;j--)
            L->list[j]=L->list[j-1];
        L->list[i]=x;
        return 1;
    }
}

int ListDelete(SeqList *L,int i ,DataType *x)
{
    int j;
    if(L->size<=0)
    {
        printf("sequence table no empty can be deleted！\n");
        return 0;
    }
    else if(i<0||i>L->size-1)
    {
        printf("parameter i wrongful！");
        return 0;
    }
    else
    {
        *x = L->list[i];
        for(j = i+1;j <= L->size-1;j++)
            L->list[j-1] = L->list[j];
        L->size--;
        return 1;
    }
}

int ListGet(SeqList L,int i,DataType *x)
{
    if(i < 0||i > L.size-1)
    {
        printf("parameter i wrongful！\n");
        return 0;
    }
    else
    {
        *x = L.list[i];
        return 1;
    }
}


int ListSearch(SeqList L,DataType x){
    for (int i = 0; i < L.size; ++i) {
        if(L.list[i] == x){
            return i;
        }
    }
    return -1;
}
int main() {
    SeqList myList;
    int i, x;
    ListInitiate(&myList);
    for (i = 0; i < 10; i++)
        ListInsert(&myList, i, i + 1);
    ListDelete(&myList, 4, &x);
    for (i = 0; i < ListLength(myList); i++) {
        ListGet(myList, i, &x);
        printf("%d", x);
    }

    int a = ListSearch(myList,9);
    int b = ListSearch(myList,11);
    printf("\n9 the search value is%d",a);
    printf("\n11 the search value is%d",b);
    return 0;
}


